package gui.options;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;

public class FollowedChannelPanel extends JPanel {
	private static final long serialVersionUID = 1L;
	private JButton removeButton = new JButton("X");
	private JToggleButton remoteButton = new JToggleButton("Remote", false);
	private JToggleButton localButton = new JToggleButton("Local", true); //TODO: set these by global settings ("Set default as local", etc.)
	
	public FollowedChannelPanel(String channelName) {
		this.remoteButton.setEnabled(false); //because i don't have any way to get chat from a remote server yet
		
		this.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
		FlowLayout layout = (FlowLayout)this.getLayout();
		layout.setHgap(2);
		layout.setVgap(1);
		layout.setAlignment(FlowLayout.LEADING);
		
		//add components below
		this.add(this.removeButton);
		this.add(new JLabel("|"));
		this.add(this.remoteButton);
		this.add(this.localButton);
		this.add(new JLabel("|"));
		this.add(new JLabel(channelName));
		
		//configure components below
		this.removeButton.setBorder(new EmptyBorder(1, 5, 1, 4)); //this changes the size of the actual button component
		
		//flip state for both buttons when one is clicked
		this.remoteButton.setBorder(new EmptyBorder(2, 5, 2, 4));
		this.remoteButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				remoteButton.setSelected(true);
				localButton.setSelected(false);
			}
		});
		
		this.localButton.setBorder(new EmptyBorder(2, 5, 2, 4));
		this.localButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				localButton.setSelected(true);
				remoteButton.setSelected(false);
			}
		});
	}
	
	public void selectLocalButton() {
		this.localButton.doClick();
	}
	
	public void selectRemoteButton() {
		this.remoteButton.doClick();
	}
	
	public void selectRemoveButton() {
		this.removeButton.doClick();
	}
}
